package com.yygo.service.impl;

import com.yygo.dao.ProvinceDao;
import com.yygo.model.City;
import com.yygo.model.Province;
import com.yygo.service.ProvinceManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by tiansha on 2015/6/24.
 */
@Service("provinceManager")
public class ProvinceManagerImpl extends GenericManagerImpl<Province, Long> implements ProvinceManager {

    private ProvinceDao provinceDao;

    @Autowired
    public ProvinceManagerImpl(ProvinceDao provinceDao) {
        super(provinceDao);
        this.provinceDao = provinceDao;
    }

    @Override
    @Cacheable(value = "allProvinces")
    public List<Province> getAll() {
        return provinceDao.getAll();
    }

    @Override
    public void clearAll() {
        provinceDao.clearAll();
    }

    @Override
    @Cacheable(value = "provinceCities", key = "#provinceName")
    public List<City> getMyCity(String provinceName) {
        return provinceDao.findByProvinceName(provinceName);
    }

    @Override
    @Cacheable(value = "provinceNames", key = "#code")
    public String getProvinceNameByCode(String code) {
        return provinceDao.getProvinceNameByCode(code);
    }
}
